package com.ruoyi.equ.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.padType.PadTypes;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.equ.service.IPadTypesService;
import com.ruoyi.pad.domain.KyDeviceInfo;
import com.ruoyi.pad.service.IKyDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 仪器树形类型分类Controller
 * 
 * @author ruoyi
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/equ/padTypes")
public class PadTypesController extends BaseController
{
    @Autowired
    private IPadTypesService padTypesService;

    @Autowired
    private IKyDeviceInfoService kyDeviceInfoService;

    /**
     * 查询仪器树形类型分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PadTypes padTypes)
    {
        startPage();
        List<PadTypes> list = padTypesService.selectPadTypesList(padTypes);
        return getDataTable(list);
    }

    /**
     * 获取设备下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect()
    {
        PadTypes padTypes = new PadTypes();
        List<String> dicts = kyDeviceInfoService.selectKyBindDevice(new KyDeviceInfo());
        if(!dicts.isEmpty()) {
            padTypes.setDictNameList(dicts);
        }
        List<PadTypes> padTypesList = padTypesService.selectPadTypesList(padTypes);
        List<TreeSelect> padTypesTree = padTypesService.buildPadTypesTreeSelect(padTypesList);
        return AjaxResult.success(padTypesTree);
    }

    /**
     * 导出仪器树形类型分类列表
     */
    @Log(title = "仪器树形类型分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PadTypes padTypes)
    {
        List<PadTypes> list = padTypesService.selectPadTypesList(padTypes);
        ExcelUtil<PadTypes> util = new ExcelUtil<PadTypes>(PadTypes.class);
        util.exportExcel(response, list, "仪器树形类型分类数据");
    }

    /**
     * 获取仪器树形类型分类详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(padTypesService.selectPadTypesById(id));
    }

    /**
     * 新增仪器树形类型分类
     */
    @Log(title = "仪器树形类型分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PadTypes padTypes)
    {
        return toAjax(padTypesService.insertPadTypes(padTypes));
    }

    /**
     * 修改仪器树形类型分类
     */
    @Log(title = "仪器树形类型分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PadTypes padTypes)
    {
        return toAjax(padTypesService.updatePadTypes(padTypes));
    }

    /**
     * 删除仪器树形类型分类
     */
    @Log(title = "仪器树形类型分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(padTypesService.deletePadTypesByIds(ids));
    }
}
